import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Calendar;

/**
 * Created by IntelliJ IDEA.
 * User: MrN
 * Date: 21.11.11
 * Time: 21:21
 * To change this template use File | Settings | File Templates.
 */

public class testDrive
{
    public static void main(String[] args)  throws ClassNotFoundException, SQLException, InterruptedException
    {

        long startMil, nowMil, difMil, kriteriumTime;

        SqlBot bot = new SqlBot();
        RSSReaderDOM parser = new RSSReaderDOM();
        ArrayList<News> listOfNews;

        Calendar timeStart = Calendar.getInstance();//start tid
       
        while(true)
        {
            try
            {
                Calendar timeNow = Calendar.getInstance();//start tid

                startMil = timeStart.getTimeInMillis();//konveretre tid til millisekunder
                nowMil = timeNow.getTimeInMillis();
                difMil = nowMil - startMil;//forskjell mellom naa og start tid
                kriteriumTime = difMil / (60 * 1000);//(24 * 60 * 60 * 1000);//kriterium til aa slette nyhetter
                System.out.println("Kriterium " + kriteriumTime);
               
                    bot.addFeed("www.dagbladet.no", "Bil", "http://www.dagbladet.no/rss/bil/");
                    bot.addFeed("www.dn.no", "IT", "http://www.dn.no/rss/?section=dagensit");
                    bot.addFeed("www.dn.no", "Børs", "http://www.dn.no/rss/?section=borsMarked");
                    bot.addFeed("www.dn.no", "Vin & mat", "http://www.dn.no/rss/?section=vinguiden ");
                    bot.addNews();
                    System.out.println("News added!!!!!");

                    //Slett gammel nyhetter hver 3 dag(naa brukes test kriterium 1 minutt)
                    if (kriteriumTime >= 1)
                    {
                        delete();
                        timeStart = Calendar.getInstance();
                    }
                //Opdatere nyheter hver 3 minutt (naa bruker vi test kjøretid 15 sekunder)
                Thread.sleep(15000);//180000

                

            }//end of try
            catch(Exception e)
            {
                System.out.println("Exception i while" + e);
            }//end of catch
        }//end of while        
    }

    public static void delete() throws ClassNotFoundException, SQLException, InterruptedException
    {
        SqlBot bot = new SqlBot();
        bot.deleteNews();
    }

}
